#
#        Python GUI - Radio Groups - Swing
#

from GRadioGroups import RadioGroup as GRadioGroup
import javax.swing as swing
from JHacks import *

class RadioGroup(GRadioGroup):

    def __init__(self, items=[], **kwds):
        GRadioGroup.__init__(self,items,**kwds)

        self._j_group=swing.ButtonGroup()
        
        self._value_dict={}

    def _item_added(self,item):
        self._j_group.add(item._j_obj)
        self._value_dict[item.value]=item
    
    def _item_removed(self,item):
        self._j_group.remove(item._j_obj)
        del self._value_dict[item.value]
    
    def _value_changed(self):
        new_button=self._value_dict[self.value]
        _j_button_model=new_button._j_obj.getModel()
        self._j_group.setSelected(_j_button_model,True)